{extend name="public/layout" /}
{block name="head"}
{/block}
{block name="body"}

<body>
  <div class="container-fluid p-t-15">
    <div class="card">
      <ul class="nav nav-tabs page-tabs">
        {volist name="group_list" id="vo"}
        <li {eq name="$vo['dict_code']" value="$group" }class="active" {/eq}>
          <a href="/system/config/index.html?group={$vo.dict_code}">{$vo.dict_value}</a>
        </li>
        {/volist}
        <li><a href="/system/config/upload.html">上传配置</a></li>
        <li><a href="/system/config/sms.html">短信配置</a></li>
        <li class="pull-right" style="padding-top:6px;">
          <button type="button" class="btn btn-primary" onclick="doAction.add('{$group}');">
            <i class="mdi mdi-plus"></i>
          </button>
          <button type="button" class="btn btn-default" onclick="doAction.refresh();">
            <i class="mdi mdi-refresh"></i>
          </button>
        </li>
      </ul>
      <div class="tab-content">
        <div class="tab-pane active">
          <form id="form" class="form-horizontal">
            <input type="hidden" name="config_group" value="{$group}" />
            {foreach $form_list as $h}
            {$h|raw}
            {/foreach}
            <div class="form-group">
              <div class="col-sm-10 col-sm-offset-2">
                <div class="pull-left">
                  <button type="button" class="btn btn-primary btn-sub">保存</button>
                  <button type="button" class="btn btn-default btn-reset">重置</button>
                </div>
                <div class="pull-left m-l-15">
                  <p class="error-msg"></p>
                </div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
  <script>
    formHelper.init();
    formHelper.subForm(function () {
      helper.refresh();
    });
    var doAction = {
      add: function (group) {
        var url = '/system/config/add.html?config_group=' + group;
        layer.open({
          type: 2,
          title: "添加配置",
          offset: "30px",
          area: helper.layerMedia('800px','528px'),
          content: url
        });
      },
      edit: function (id) {
        var url = '/system/config/edit.html?id=' + id;
        layer.open({
          type: 2,
          title: "修改配置",
          offset: "30px",
          area: helper.layerMedia('800px','528px'),
          content: url
        });
      },
      refresh: function () {
        helper.getAjax({
          url: "/system/config/refresh.html",
          success: function () {
            helper.refresh();
          }
        })
      },
      del: function (id) {
        layer.confirm('确认删除该配置吗?', { icon: 3 },
          function (index) {
            helper.getAjax({
              url: '/system/config/del.html',
              data: { id: id },
              success: function (res) {
                if (res.code == 1) {
                  helper.refresh();
                } else {
                  layer.msg(res.msg);
                }
                layer.close(index);
              }
            })
          }
        )
      }
    };
  </script>
</body>
{/block}